package com.gientech.elasticsearchdemo.service.impl;

import com.gientech.elasticsearchdemo.entity.Book;
import com.gientech.elasticsearchdemo.repository.BookRepository;
import com.gientech.elasticsearchdemo.service.BookService;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Resource
    private BookRepository bookRepository;

    @Resource
    private ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Override
    public void deleteById(String id) {
        elasticsearchRestTemplate.delete(id, Book.class);
    }

    @Override
    public void save(Book book) {
        bookRepository.save(book);
    }

    @Override
    public void saveAll(List<Book> list) {
        bookRepository.saveAll(list);
    }

    @Override
    public Iterator<Book> findAll() {
        return bookRepository.findAll().iterator();
    }
}
